package cn.zhx.Proxy.demo.JDKProxy;



import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

//代理工厂，用来创建代理对象
public class ProxyFactory {
    //被代理对象
    private TrainStation trainStation = new TrainStation();

    public SellTickets getProxyObject(){
        return (SellTickets)Proxy.newProxyInstance(
                trainStation.getClass().getClassLoader(),
                trainStation.getClass().getInterfaces(),
                new InvocationHandler() {
                    @Override
                    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                        System.out.println("收取一些费用");
                        return method.invoke(trainStation,args);
                    }
                }
        );
    }
}
